



alter    trigger td_trader_ai
on dbo.td_trader for insert
as
begin
  set nocount on
  declare @traderid int,
    @name varchar(60),
    @client bit,
    @cash bit,
    @sursubid int,
    @subjectid int
  declare curtrader cursor local forward_only static optimistic for
    select i.traderid,i.name,i.client,i.iscash,i.sursubid,i.subjectid from inserted i
  open curtrader
  fetch next from curtrader into @traderid,@name,@client,@cash,@sursubid,@subjectid
  while @@fetch_status = 0
  begin    
    if @cash=0 and @sursubid is null and @subjectid is null
      exec p_maketradersubject @client,@traderid,@name
    fetch next from curtrader into @traderid,@name,@client,@cash,@sursubid,@subjectid	
  end
  close curtrader
  deallocate curtrader
end





